<?php

$params = require(__DIR__ . '/params.php');
$db_dev = require(__DIR__ . '/db_dev.php');
$db_test = require(__DIR__ . '/db_test.php');
$db_production = require(__DIR__ . '/db_production.php');

$config = [
    'id' => 'basic',
    'name' => '玲珑手游加速器',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'components' => [
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'ruleTable' => 'admin_rule',
            'itemTable' => 'admin_item',
            'itemChildTable' => 'admin_item_child',
            'assignmentTable' => 'admin_assignment',
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'ycOD4A7BBg5T31XmFvz1RMoqjT70EUt9',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\AdminUserIdentity',
            'enableAutoLogin' => true,
        ],
        'adminUser'     => [
            'class'           => yii\web\User::class,
            'identityClass'   => app\models\User::class,
            'enableAutoLogin' => true,
            'loginUrl'        => ['admin/site/login'],
            'identityCookie'  => ['name' => '__admin_identity', 'httpOnly' => true],
            'idParam'         => '_admin',
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '' => 'site/index',
                'news' => 'info/news',
                'notice' => 'info/notice',
                'about' => 'info/about',
                'news/<id:\d+>' => 'info/news-detail',
                'notice/<id:\d+>' => 'info/notice-detail',
            ],
        ],
        'wechat' => [
            'class' => 'maxwen\easywechat\Wechat',
            // 'userOptions' => []  # user identity class params
            // 'sessionParam' => '' # wechat user info will be stored in session under this key
            // 'returnUrlParam' => '' # returnUrl param stored in session
        ],
    ],
    'params' => $params,
    'modules' => [
        'admin' => [
            'class' => 'app\modules\admin\admin',
        ],
        'admin-rabc' => [
            'class' => 'mdm\admin\Module',
            'layout' => 'left-menu'
        ]
    ],
    'aliases' => [
         '@mdm/admin' => '@vendor/mdmsoft/yii2-admin',
    ],
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

if (YII_ENV == 'prod') {
    $config['components']['db'] = $db_production;
} else if (YII_ENV == 'test') {
    $config['components']['db'] = $db_test;
} else {
    $config['components']['db'] = $db_dev;
}

return $config;
